package com.lbssoft.gpsbd.dao.sql;

import com.lbssoft.gpsbd.model.Device;
import com.lbssoft.gpsbd.model.vo.UserParam;
import com.mysql.jdbc.StringUtils;
import org.apache.ibatis.jdbc.SQL;

public class UserSql {
	private static final String TABLE_NAME = "lbs_users";

	public String update(final UserParam user) {
		return new SQL(){
			{
				UPDATE(TABLE_NAME);

				// 通过条件 判断是否需要更新该字段
				if (!StringUtils.isNullOrEmpty(user.getEmail())) {
					SET("email = #{email}");
				}else{
					SET("email = null");
				}

				if (!StringUtils.isNullOrEmpty(user.getPhone())) {
					SET("phone = #{phone}");
				}else{
					SET("phone = null");
				}
				SET("disabled = #{disabled}");
				WHERE("id= #{id}");

			}
		}.toString();
	}
	
}
